home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-26 | 8.4 KB | 354 lines | [TEXT/MPS ] |
- //==========================================================
- //
- // File: BeeperPart.cpp
- // Release Version: $ 1.0d9 $
- //
- // Author: Henri Lamiraux
- // Modified by M.Boetcher to accept Dropped and Pasted sounds
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //==========================================================
-
- #ifndef BEEPERPART_H
- #include "BeeperPart.h"
- #endif
-
- #ifndef BEEPERDEF_H
- #include "BeeperDef.h"
- #endif
-
- #ifndef BEEPERSEL_H
- #include "BeeperSel.h"
- #endif
-
- #ifndef ACTIONS_H
- #include "Actions.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWPUSHBU_H
- #include "FWPushBu.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWNOTIFN_H
- #include <FWNotifn.h>
- #endif
-
- #ifndef FWCLAINF_H
- #include <FWClaInf.h>
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- // ----- Macintosh Includes -----
- #if defined(FW_BUILD_MAC) && !defined(__SOUND__)
- #include <Sound.h>
- #endif
-
-
- //==========================================================
- // Runtime Information
- //==========================================================
-
- #pragma segment BeeperPart
-
- //==========================================================
- // Globals
- //==========================================================
-
- const ODValueType CBeeperPart::kPartKind = kODFBeeperKind;
-
- //==========================================================
- // class CBeeperPart
- //==========================================================
-
- //----------------------------------------------------------
- // CBeeperPart::CBeeperPart
- //----------------------------------------------------------
-
- CBeeperPart::CBeeperPart(ODPart* odPart) :
- FW_CPart(odPart, CBeeperPart::kPartKind),
- fAction(NULL)
- {
- }
-
- //----------------------------------------------------------
- // CBeeperPart::~CBeeperPart
- //----------------------------------------------------------
-
- CBeeperPart::~CBeeperPart()
- {
- delete fAction;
- }
-
- //----------------------------------------------------------
- // CBeeperPart::Initialize
- //----------------------------------------------------------
-
- void CBeeperPart::Initialize(Environment* ev)
- {
- FW_CPart::Initialize(ev);
-
- // ----- Register our Presentation
- CBeeperSelection *selection =
- new CBeeperSelection(ev, this);
- RegisterPresentation(ev, kODFBeeperPresentation,
- TRUE, selection);
- }
-
- //----------------------------------------------------------
- // CBeeperPart::NewFrame
- //----------------------------------------------------------
-
- FW_CFrame* CBeeperPart::NewFrame(Environment* ev,
- ODFrame* frame,
- FW_CPresentation* presentation,
- FW_Boolean storage)
- {
- return new CBeeperFrame(ev, frame, presentation, this);
- }
-
- //----------------------------------------------------------
- // CBeeperPart::InternalizeContent
- //----------------------------------------------------------
-
- void CBeeperPart::InternalizeContent(Environment *ev,
- ODStorageUnit* storage,
- FW_CCloneInfo* cloneInfo)
- {
- FW_ASSERT(fAction == NULL);
-
- if (CScriptAction::IsInStorage(ev, storage))
- fAction = new CScriptAction();
- else if (CSoundAction::IsInStorage(ev, storage))
- fAction = new CSoundAction();
-
- if (fAction != NULL)
- fAction->Internalize(ev, storage);
- }
-
- //----------------------------------------------------------
- // CBeeperPart::ExternalizeContent
- //----------------------------------------------------------
- void CBeeperPart::ExternalizeContent(Environment *ev,
- ODStorageUnit* storage,
- FW_CCloneInfo* cloneInfo)
- {
- // If any kind of property content exists...
- if (storage->Exists(ev, kODPropContents, kODNULL, 0))
- {
- storage->Focus(ev, kODPropContents,
- kODPosUndefined, kODNULL, 0, kODPosAll);
- storage->Remove(ev);
- }
- storage->AddProperty(ev, kODPropContents);
- if (fAction != NULL)
- fAction->Externalize(ev, storage);
- }
-
- //----------------------------------------------------------
- // CBeeperPart::DoAction
- //----------------------------------------------------------
- void CBeeperPart::DoAction()
- {
- if (fAction != NULL)
- fAction->DoIt();
- }
-
- //------------------------------------------------------------------------------
- // CBeeperPart::SetAction
- //------------------------------------------------------------------------------
-
- void CBeeperPart::SetAction(CAction *action)
- {
- if (action!=NULL && action!=fAction)
- {
- delete fAction;
- fAction = action;
- }
- }
-
- //==========================================================
- // class CBeeperFrame
- //==========================================================
-
- //----------------------------------------------------------
- // CBeeperFrame::CBeeperFrame
- //----------------------------------------------------------
-
- CBeeperFrame::CBeeperFrame(Environment* ev,
- ODFrame* frame,
- FW_CPresentation* presentation,
- CBeeperPart* part) :
- FW_CFrame(ev, frame, presentation, part),
- fBeeperPart(part),
- fBeeper(NULL),
- fButtonId(0),
- fConnection(this),
- fButtonNotificationToken(0)
- {
- fConnection.Connect();
- this->AddToFocusSet(ev,part->GetClipboardFocusToken(ev));
- SetDroppable(ev, TRUE);
- }
-
- //----------------------------------------------------------
- // CBeeperFrame::~CBeeperFrame
- //----------------------------------------------------------
-
- CBeeperFrame::~CBeeperFrame()
- {
- FW_CInterest interest(fBeeper, fButtonNotificationToken);
- fConnection.RemoveInterest(interest);
- }
-
- //----------------------------------------------------------
- // CBeeperFrame::CreateGadgetLayout
- //----------------------------------------------------------
-
- void CBeeperFrame::CreateGadgetLayout(Environment* ev,
- FW_CGadgetInitializer& initializer)
- {
- FW_CDynamicString label("Beep");
-
- FW_CRect frameRect;
- this->GetFrameShapeBounds(ev, frameRect);
-
- fBeeper = FW_NEW(FW_CPushButton,
- (ev, initializer, this, fButtonId,
- frameRect[FW_kTopLeft], frameRect[FW_kBotRight],
- label));
- fBeeper->SetDefault(ev, false);
-
- fButtonNotificationToken =
- fBeeper->GetButtonPressedNotificationToken(ev);
- FW_CInterest interest(fBeeper, fButtonNotificationToken);
- fConnection.AddInterest(interest);
- }
-
- //----------------------------------------------------------
- // CBeeperFrame::CanAcceptDrop
- //----------------------------------------------------------
-
- ODDragResult CBeeperFrame::CanAcceptDrop(Environment* ev,
- ODDragItemIterator* dragInfo)
- {
- ODDragResult acceptDrop =
- FW_CFrame::CanAcceptDrop(ev, dragInfo);
-
- if (!acceptDrop)
- {
- for (ODStorageUnit *dragSU = dragInfo->First(ev);
- dragSU != NULL;
- dragSU = dragInfo->Next(ev))
- {
- if (CSoundAction::IsInStorage(ev, dragSU))
- return TRUE;
- if (CScriptAction::IsInStorage(ev, dragSU))
- return TRUE;
- }
- }
-
- return acceptDrop;
- }
-
- //----------------------------------------------------------
- // CBeeperFrame::Draw
- //----------------------------------------------------------
-
- void CBeeperFrame::Draw(Environment* ev,
- ODFacet* facet,
- ODShape* invalidShape)
- {
- FW_CFacetContext fc(ev, facet, invalidShape);
-
- // Just erase and assume gadgets will draw
- FW_CRect invalidRect;
- fc.GetClipRect(invalidRect);
- FW_CRectShape::RenderRect(fc, invalidRect,
- FW_kFill, FW_kWhiteEraseInk);
- }
-
- //----------------------------------------------------------
- // CBeeperFrame::HandleNotification
- //----------------------------------------------------------
-
- void CBeeperFrame::HandleNotification(
- const FW_CNotification& notification)
- {
- const FW_CButtonPressedNotification& buttonPressed =
- (FW_CButtonPressedNotification&) notification;
-
- if (buttonPressed.GetButtonId() == fButtonId)
- {
- fBeeperPart->DoAction();
- }
- }
-
- //----------------------------------------------------------
- // CBeeperFrame::FrameShapeChanged
- //----------------------------------------------------------
-
- void CBeeperFrame::FrameShapeChanged(Environment* ev)
- {
- FW_CFrame::FrameShapeChanged(ev);
-
- // Resize the Beeper to fit the new frame size
- FW_CRect frameRect;
- this->GetFrameShapeBounds(ev, frameRect);
- fBeeper->SetSize(ev, frameRect.BotRight());
-
- // Redraw the entire frame
- this->Invalidate(ev);
- }
-